/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.games.epkb.entityClasses;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author plebani
 */
@Entity
@Table(name = "cpu")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Cpu.findAll", query = "SELECT c FROM Cpu c"),
    @NamedQuery(name = "Cpu.findById", query = "SELECT c FROM Cpu c WHERE c.id = :id"),
    @NamedQuery(name = "Cpu.findByCoresNumber", query = "SELECT c FROM Cpu c WHERE c.coresNumber = :coresNumber"),
    @NamedQuery(name = "Cpu.findByTotalFrequency", query = "SELECT c FROM Cpu c WHERE c.totalFrequency = :totalFrequency")})
public class Cpu implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "ID")
    private String id;
    @Column(name = "CoresNumber")
    private Integer coresNumber;
    @Column(name = "TotalFrequency")
    private Long totalFrequency;
    @JoinColumn(name = "Id_Server", referencedColumnName = "ID")
    @ManyToOne
    private Server idServer;
    @JoinColumn(name = "ID", referencedColumnName = "ID", insertable = false, updatable = false)
    @OneToOne(optional = false)
    private Component component;
    @OneToMany(mappedBy = "idCPU")
    private Collection<CpuCorePower> cpuCorePowerCollection;
    @OneToMany(mappedBy = "idCPU")
    private Collection<CpuCore> cpuCoreCollection;

    public Cpu() {
    }

    public Cpu(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Integer getCoresNumber() {
        return coresNumber;
    }

    public void setCoresNumber(Integer coresNumber) {
        this.coresNumber = coresNumber;
    }

    public Long getTotalFrequency() {
        return totalFrequency;
    }

    public void setTotalFrequency(Long totalFrequency) {
        this.totalFrequency = totalFrequency;
    }

    public Server getIdServer() {
        return idServer;
    }

    public void setIdServer(Server idServer) {
        this.idServer = idServer;
    }

    public Component getComponent() {
        return component;
    }

    public void setComponent(Component component) {
        this.component = component;
    }

    @XmlTransient
    public Collection<CpuCorePower> getCpuCorePowerCollection() {
        return cpuCorePowerCollection;
    }

    public void setCpuCorePowerCollection(Collection<CpuCorePower> cpuCorePowerCollection) {
        this.cpuCorePowerCollection = cpuCorePowerCollection;
    }

    @XmlTransient
    public Collection<CpuCore> getCpuCoreCollection() {
        return cpuCoreCollection;
    }

    public void setCpuCoreCollection(Collection<CpuCore> cpuCoreCollection) {
        this.cpuCoreCollection = cpuCoreCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Cpu)) {
            return false;
        }
        Cpu other = (Cpu) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.games.epkb.entityClasses.Cpu[ id=" + id + " ]";
    }
    
}
